//
//  NextController.swift
//  MSwift
//
//  Created by 马龙波 on 2017/10/31.
//  Copyright © 2017年 马龙波. All rights reserved.
//

import UIKit
import XRCarouselView

class NextController: BaseController {

    fileprivate let arr = [
        "http://pic39.nipic.com/20140226/18071023_162553457000_2.jpg",//网络图片
        UIImage.init(named: "ph375x200") as Any,
        "http://photo.l99.com/source/11/1330351552722_cxn26e.gif",//网络gif图片
    ];
    
    fileprivate let describeArray = ["网络图片", "本地图片", "网络动态图"];
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = "下一页"
        view.backgroundColor = UIColor.white
        
        view.addSubview(tableView)

    }

    override func viewWillDisappear(_ animated: Bool) {
        self.navigationController?.navigationBar .setBackgroundImage(UIImage.init(named: "navi_pic"), for: .default)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        self.navigationController?.navigationBar .setBackgroundImage(UIImage.init(named: "nabg"), for: .default)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    fileprivate lazy var tableView : UITableView = {
        let temTableView = UITableView(frame: CGRect(x: 0, y: 0, width: kScreenW, height: kScreenH-kNavgationH), style: .plain)
        temTableView.delegate = self
        temTableView.dataSource = self
        temTableView.tableFooterView = UIView()
        temTableView.tableHeaderView = carouseView
        return temTableView
    }()
    
    fileprivate lazy var carouseView : XRCarouselView = {
        let temCarouseView = XRCarouselView(frame: CGRect(x: 0, y: 0, width: kScreenW, height: 200))
        temCarouseView.placeholderImage = UIImage.init(named: "ph375x200")
        temCarouseView.time = 2
        temCarouseView.imageArray = arr
        temCarouseView.describeArray = describeArray
        temCarouseView.imageClickBlock = { inter in
            kLog("inter->\(inter)")
        }
        
        return temCarouseView
    }()
}

extension NextController :UITableViewDelegate,UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 20
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50.0
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let identifier = "mycell"
        var cell = tableView.dequeueReusableCell(withIdentifier: identifier)
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: identifier)
        }
        cell?.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
        cell?.textLabel?.text = "cell->\(indexPath.row)"
        
        return cell!
        
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    }
}
